package top.malaoshi.ctrl;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import top.malaoshi.model.Result;
import top.malaoshi.service.LoginSrvImpl;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


@RestController
//@CrossOrigin( allowCredentials = "true")
public class LoginCtrl {

    @Resource
    private LoginSrvImpl srv;

    @RequestMapping("/doLogin")
//    public Result doLogin(String phone, String password, HttpServletRequest request){
//        HttpSession session=request.getSession();
    public Result doLogin(@RequestParam(value = "field1",required = false) String phone,@RequestParam(value = "field2",required = false) String password, HttpSession session){
        System.out.println("sessionid:"+session.getId());
        String userinfo=(String)session.getAttribute("userinfo");
        System.out.println("userinfo:"+userinfo);

        if(userinfo==null || "".equals(userinfo)){
            System.out.println("向session放入数据");
            session.setAttribute("userinfo","phone");
        }

        System.out.println(phone+"---"+password);

        Result res=srv.login(phone,password);
        return res;
    }
}
